home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Programmation / jedit / jedit5.1.0install.exe / {app} / macros / Editing / Duplicate_Lines_Above.bsh next >
Text File  |  2013-07-28  |  2KB  |  74 lines

  1. /*
  2.  * Duplicate_Lines_Above.bsh - a BeanShell macro script for the
  3.  * jEdit text editor - duplicates the cursor line.
  4.  * Copyright (C) 2001 Francesc Roses
  5.  * Copyright (c) 2008 encorejane
  6.  *
  7.  * This program is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU General Public License
  9.  * as published by the Free Software Foundation; either version 2
  10.  * of the License, or any later version.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with the jEdit program; if not, write to the Free Software
  19.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  * based on: Duplicate_Line.bsh 3866 2001-11-06 15:04:21Z jgellene
  21.  *
  22.  * Checked for jEdit 4.3 API
  23.  *
  24.  */
  25.  
  26. //Localization
  27. final static String NotEditableMessage = jEdit.getProperty("macro.rs.general.ErrorNotEditableDialog.message", "Buffer is not editable");
  28.  
  29. // Process
  30. void duplicateLinesAbove()
  31. {
  32.     /*
  33.      * Guard for readonly files because Buffer.insert()
  34.      * ignores the flag
  35.      *
  36.      */
  37.     if(buffer.isReadOnly())
  38.     {
  39.         Macros.error(view, NotEditableMessage);
  40.         return;
  41.     }
  42.  
  43.     selections = textArea.getSelectedLines();
  44.     if(selections.length == 0){
  45.         selections = new int [] {textArea.getCaretLine()};
  46.     }
  47.     start = textArea.getLineStartOffset(selections[0]);
  48.     stop = textArea.getLineEndOffset(selections[selections.length-1]);
  49.     if(stop-1 == textArea.getBufferLength()){
  50.         text = textArea.getText(start,stop-start-1)+'\n';
  51.     }else{
  52.         text = textArea.getText(start,stop-start);
  53.     }
  54.     buffer.insert(start, text);
  55. }
  56.  
  57. duplicateLinesAbove();
  58.  
  59. /*
  60.  
  61. Macro index data (in DocBook format)
  62.  
  63.   <listitem>
  64.     <para><filename>Duplicate_Line.bsh</filename></para>
  65.     <abstract><para>
  66.       Duplicates the line on which the caret lies immediately
  67.       above it.
  68.     </para></abstract>
  69.   </listitem>
  70.  
  71. */
  72.  
  73. // end Duplicate_Line.bsh
  74.